package javaMultiThreadInAction.chapter04;

import javaMultiThreadInAction.util.Tools;

import java.io.*;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description some description
 * @date 2024/1/16 11:21:24
 */
public class SimpleStatTask extends AbstractStatTask{
   private final InputStream in;

    public SimpleStatTask(InputStream in, int sampleInterval, int traceIdDiff, String expectedOperationName, String expectedExternalDeviceList) {
        super(sampleInterval, traceIdDiff, expectedOperationName, expectedExternalDeviceList);

        this.in = in;
    }

    @Override
    protected void doCalculate() throws IOException, InterruptedException {
        String strBufferSize = System.getProperty("x.input.buffer");
        int inputBufferSize = null != strBufferSize ? Integer.valueOf(strBufferSize) : 8192 *4;
        final BufferedReader logFileReader = new BufferedReader(new InputStreamReader(in), inputBufferSize);
        String record;
        try {
            while ((record = logFileReader.readLine()) != null) {
                recordProcessor.process(record);
            }
        } finally {
            Tools.silentClose();
        }
    }
}
